﻿namespace KnownCMS.Entities;

partial class CmCategory
{
    /// <summary>
    /// 取得或设置上级类别对象。
    /// </summary>
    public virtual CmCategory Parent { get; set; }

    /// <summary>
    /// 取得或设置下级类别列表。
    /// </summary>
    public virtual List<CmCategory> Children { get; set; } = [];

    /// <summary>
    /// 取得类别全部级别的全名。
    /// </summary>
    public virtual string FullName
    {
        get
        {
            if (Parent != null)
                return Parent.FullName + "/" + Name;

            return Name;
        }
    }

    /// <summary>
    /// 取得更新日志URL。
    /// </summary>
    public virtual string LogUrl => Url.GetLogUrl(Code);

    /// <summary>
    /// 取得文档板块URL。
    /// </summary>
    public virtual string DocUrl => Url.GetDocUrl(Code);

    /// <summary>
    /// 取得API板块URL。
    /// </summary>
    public virtual string ApiUrl => Url.GetApiUrl(Code);

    /// <summary>
    /// 取得交流板块URL。
    /// </summary>
    public virtual string BbsUrl => Url.GetBbsUrl(Code);

    internal CmCategory AddChild(CmCategory child)
    {
        child.Parent = this;
        Children ??= [];
        Children.Add(child);
        return child;
    }
}